package com.stox.ui.javafx.core.widget;

import javafx.scene.control.TreeCell;

import com.stox.dto.Scrip;
import com.stox.dto.intf.Iconifiable;
import com.stox.dto.intf.Nameable;
import com.stox.ui.javafx.core.widget.wrapper.ImageView;

public abstract class NameableTreeCell<T extends Nameable> extends TreeCell<T> {

	@Override
	protected void updateItem(T nameable, boolean empty) {
		super.updateItem(nameable, empty);
		if(null == nameable){
			setText(null);
			setGraphic(null);
			getStyleClass().remove("scrip-tree-cell");
		}else{
			setText(nameable.getName());
			
			if(nameable instanceof Scrip){
				getStyleClass().add("scrip-tree-cell");
			}else{
				getStyleClass().remove("scrip-tree-cell");
			}
			
			if(nameable instanceof Iconifiable){
				Iconifiable iconifiable = (Iconifiable)nameable;
				setGraphic(new ImageView(iconifiable.getIconPath()));
			}else{
				setGraphic(null);
			}
		}
	}
	
}
